home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_MacPaint / Source / shared.subproj / ResultObject.m < prev    next >
Text File  |  1995-06-12  |  36KB  |  823 lines

  1. /***********************************************************************\
  2. Common class providing a multiple-result interface in all Convert objects
  3. Copyright (C) 1993 David John Burrowes
  4.  
  5. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version.
  6.  
  7. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  8.  
  9. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  10.  
  11. The author, David John Burrowes, can be reached at:
  12.     davidjohn@kira.net.netcom.com
  13.     David John Burrowes
  14.     1926 Ivy #10
  15.     San Mateo, CA 94403-1367
  16. \***********************************************************************/
  17.  
  18. /*
  19. ====================================================================
  20. This is the implementation file for the ResultObject class.  Full documentation for this class can be found in the ResultObject.rtf file.  I will not duplicate all that fine information here.
  21.     This is $Revision: 1.4 $ of this file
  22.     It was last modified by $Author: death $ on $Date: 93/04/04 23:45:10 $
  23. Note that this file was created while using the New Century Schoolbook Roman typeface.  You may find that some things line up strangely if you don't use that family.
  24. $Log:    ResultObject.m,v $
  25. Revision 1.4  93/04/04  23:45:10  death
  26. Sun Apr  4 23:45:09 PDT 1993
  27.  
  28. Revision 1.3  93/01/10  15:08:44  death
  29. Sun Jan 10 15:08:44 PST 1993
  30.  
  31. Revision 1.2  92/07/26  13:59:14  death
  32. Update of the result object...
  33.  
  34. ====================================================================
  35. */
  36.  
  37. //
  38. //    Import our own definition
  39. //
  40. #import "ResultObject.h"
  41. #import <strings.h>
  42. #import <stdlib.h>
  43. #import <memory.h>
  44.  
  45. @implementation ResultObject
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  53. //    Routine:        CopyCString:
  54. //    Parameters:    a string that we want to copy and store
  55. //    Returns:        self
  56. //    Description:
  57. //        Stores the specified string in the first storage area for returned data.  The
  58. //        string is copied first.
  59. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  60. - (Instance) CopyCString: (CString) data
  61. {
  62.     return [self CopyCString: data Into: FIRST_RESULT];
  63. }
  64.  
  65. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  66. //    Routine:        CopyCString:Into:
  67. //    Parameters:    a string, and location to store it
  68. //    Returns:        self
  69. //    Description:
  70. //        Attempts to make a copy of the string.  If we succeed, we store it in the requested
  71. //        position, otherwise, we do nothing but post an error!!!.
  72. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  73. - (Instance) CopyCString: (CString) data Into: (Integer) reference
  74. {
  75.     GenericType    theData;
  76.     Integer    status;
  77.     CString    tempStr;
  78.     
  79.     tempStr = (char*) malloc(strlen(data)+1);
  80.     if (tempStr == NullCString)
  81.         status = ERR_CANTSTORE;
  82.     else
  83.     {
  84.         strcpy(tempStr, data);
  85.         theData.cstring = tempStr;
  86.         [self PutData: theData WithType: TYPE_CSTRING  Into: reference DoIOwn: YES];
  87.         status = [self GetMyError];
  88.         if (status != ERR_OK)
  89.             free(tempStr);
  90.     }
  91.     [self StoreMyError: status];
  92.     return self;
  93. }
  94.  
  95. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  96. //    Routine:        CopyPointer:WithLength:
  97. //    Parameters:    a pointer, and the length of its data
  98. //    Returns:        self
  99. //    Description:
  100. //        Stores the specified data in the first storage area.  Copies the data that the
  101. //        pointer points to, first..
  102. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  103. - (Instance) CopyPointer: (Pointer) data WithLength: (PositiveInteger) length 
  104. {
  105.     return [self CopyPointer: data WithLength: length Into: FIRST_RESULT];
  106. }
  107.  
  108. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  109. //    Routine:        CopyPointer:WithLength:Into:
  110. //    Parameters:    data item, and location to store it
  111. //    Returns:        self
  112. //    Description:
  113. //        Stores the specified data in the specified storage area.  To do this, we build
  114. //    a data type with our data and its type, and then we ask to store it properly.
  115. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  116. - (Instance) CopyPointer: (Pointer) data WithLength: (PositiveInteger) length Into: (Integer) reference
  117. {
  118.     GenericType    theData;
  119.     Integer    status;
  120.     Pointer    tempPtr;
  121.     
  122.     tempPtr = (Pointer) malloc(length);
  123.     if (tempPtr == NullPointer)
  124.         status = ERR_CANTSTORE;
  125.     else
  126.     {
  127.         bcopy(data, tempPtr, length);
  128.         theData.pointer = tempPtr;
  129.         [self PutData: theData WithType: TYPE_POINTER  Into: reference DoIOwn: YES];
  130.         status = [self GetMyError];
  131.         if (status != ERR_OK)
  132.             free(tempPtr);
  133.     }
  134.     [self StoreMyError: status];
  135.     return self;
  136. }
  137.  
  138.  
  139. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  140. //    Routine:        init
  141. //    Parameters:    none
  142. //    Returns:        self
  143. //    Description:
  144. //        This initalizes this object.  What this means is simply that we call the parent
  145. //        to init, and then clear all our storage areas
  146. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  147. - (Instance) init
  148. {
  149.     Integer    index;
  150.     StorageArea*    SA;    // pointer to the storage area we want to work on.
  151.  
  152.     [super init];
  153.     //
  154.     //    Now, clear our storage areas.  We can't use ResetResults, because if there is
  155.     //    junk somewhere in there, it might try to free some string or ptr that doesn't exist...
  156.     //
  157.     for (index = 0; index < MAXAREAS; index++)
  158.     {
  159.         SA = &ReturnVals[index];    // Esentially doing a pascal WITH ReturnVals[index]...
  160.         SA->StoredData.type = TYPE_NONE;
  161.         SA->StoredData.data.integer = 0;
  162.         SA->IOwnData = NO;
  163.     }
  164.     return self;
  165. }
  166.  
  167.  
  168. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  169. //    Routine:        free
  170. //    Parameters:    none
  171. //    Returns:        self
  172. //    Description:
  173. //        Clears anything about us, then asks the parent to clear themselves too...
  174. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  175. - free
  176. {
  177.     [self ResetResults];
  178.     [super free];
  179.     return self;
  180. }
  181.  
  182.  
  183. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  184. //    Routine:        GetBoolean
  185. //    Parameters:    none
  186. //    Returns:        a boolean value
  187. //    Description:
  188. //        Retrieves the boolean value, if any, from the first storage area, and returns it.
  189. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  190. - (Boolean) GetBoolean
  191. {
  192.     return [self GetBooleanFrom: FIRST_RESULT];
  193. }
  194.  
  195. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  196. //    Routine:        GetBooleanFrom:
  197. //    Parameters:    an integer indicating which storage area to retrieve from
  198. //    Returns:        a Boolean value
  199. //    Description:
  200. //        Retrieves the boolean value, if any, from the storage area specified.
  201. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  202. - (Boolean) GetBooleanFrom: (Integer) reference
  203. {
  204.     GenericType data;
  205.     
  206.     data = [self GetDataWithType: TYPE_BOOLEAN From: reference];
  207.     if ([self GetMyError] == ERR_OK)
  208.         return data.boolean;
  209.         else return NO;
  210. }
  211.  
  212. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  213. //    Routine:        GetCharacter
  214. //    Parameters:    none
  215. //    Returns:        a character value
  216. //    Description:
  217. //        Retrieves the character value, if any, from the first storage area, and returns it.
  218. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  219. - (Character) GetCharacter
  220. {
  221.     return [self GetCharacterFrom: FIRST_RESULT];
  222. }
  223.  
  224.  
  225. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  226. //    Routine:        GetCharacterFrom:
  227. //    Parameters:    an integer indicating which storage area to retrieve from
  228. //    Returns:        a character value
  229. //    Description:
  230. //        Retrieves the character value, if any, from the storage area specified.
  231. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  232. - (Character) GetCharacterFrom: (Integer) reference
  233. {
  234.     GenericType data;
  235.     
  236.     data = [self GetDataWithType: TYPE_CHARACTER From: reference];
  237.     if ([self GetMyError] == ERR_OK)
  238.         return data.character;
  239.         else return (Character) 0;
  240. }
  241.  
  242. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  243. //    Routine:        GetCString
  244. //    Parameters:    none
  245. //    Returns:        a Cstring value
  246. //    Description:
  247. //        Retrieves the cstring value, if any, from the first storage area, and returns it.
  248. //        This assumes that GetCString has already made a copy of the data to return
  249. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  250. - (CString) GetCString
  251. {
  252.     return [self GetCStringFrom: FIRST_RESULT];
  253. }
  254.  
  255.  
  256. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  257. //    Routine:        GetCStringFrom
  258. //    Parameters:    a number indicating which storage area to retrieve from
  259. //    Returns:        a Cstring value
  260. //    Description:
  261. //        Retrieves the cstring value, if any, from the specified storage area, and returns it.
  262. //        We always make a copy of the string and then return the copy.
  263. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  264. - (CString) GetCStringFrom: (Integer) reference
  265. {
  266.     GenericType data;
  267.     CString tempStr = NullCString;
  268.     
  269.     data = [self GetDataWithType: TYPE_CSTRING From: reference];
  270.     if ([self GetMyError] == ERR_OK)
  271.     {
  272.         tempStr = (CString) malloc(strlen(data.cstring)+1);
  273.         if (tempStr == NullCString)
  274.         {
  275.             [self StoreMyError: ERR_CANTSTORE];
  276.             free(tempStr);
  277.             tempStr = NullCString;
  278.         }
  279.         else
  280.             strcpy(tempStr, data.cstring);
  281.     }
  282.     return tempStr;
  283. }
  284.  
  285.  
  286. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  287. //    Routine:        GetDataWithType:From:
  288. //    Parameters:    none
  289. //    Returns:        a generic type value
  290. //    Description:
  291. //        Locates a data value in the storage area specified by storage.  If it matches
  292. //        the requested type, return it.  Otherwise, post an error.
  293. //        At present, we ignore the owning flag...
  294. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  295. - (GenericType) GetDataWithType: (Integer) theType From: (Integer) storage;
  296. {
  297.     Integer status;
  298.     GenericType theData;
  299.     
  300.     if ((storage > MAXAREAS -1) || (storage < 0))
  301.         status = ERR_NOSUCHAREA;
  302.     else
  303.     {
  304.         if (ReturnVals[storage].StoredData.type != theType)
  305.         {
  306.             status = ERR_NOSUCHTYPE;
  307.             theData.integer = 0;
  308.         }
  309.         else
  310.         {
  311.             theData = ReturnVals[storage].StoredData.data;
  312.             status = ERR_OK;
  313.         }
  314.     }
  315.     [self StoreMyError: status];
  316.     return theData;
  317. }
  318.  
  319.  
  320. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  321. //    Routine:        GetErrorCode
  322. //    Parameters:    none
  323. //    Returns:        an integer value
  324. //    Description:
  325. //        Retrieves an error code from the main error code storage area.
  326. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  327. - (Integer) GetErrorCode
  328. {
  329.     return [self GetIntegerFrom: ERRORCODE_RESULT];
  330. }
  331.  
  332.  
  333. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  334. //    Routine:        GetErrorText
  335. //    Parameters:    none
  336. //    Returns:        a CString value
  337. //    Description:
  338. //        Retrieves a string from the error string result area, and returns it to the
  339. //        caller.  Note that this does mean it retrieves and returns a copy..
  340. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  341. - (CString) GetErrorText
  342. {
  343.     return [self GetCStringFrom: ERRORTEXT_RESULT];
  344. }
  345.  
  346.  
  347. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  348. //    Routine:        GetInteger
  349. //    Parameters:    none
  350. //    Returns:        an integer value
  351. //    Description:
  352. //        Retrieves the integer value, if any, from the first storage area.
  353. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  354. - (Integer) GetInteger
  355. {
  356.     return [self GetIntegerFrom: FIRST_RESULT];
  357. }
  358.  
  359.  
  360. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  361. //    Routine:        GetIntegerFrom:
  362. //    Parameters:    an integer indicating which storage area to retrieve from
  363. //    Returns:        a Boolean value
  364. //    Description:
  365. //        Retrieves the boolean value, if any, from the storage area specified.
  366. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  367. - (Integer) GetIntegerFrom: (Integer) reference
  368. {
  369.     GenericType data;
  370.     
  371.     data = [self GetDataWithType: TYPE_INTEGER From: reference];
  372.     if ([self GetMyError] == ERR_OK)
  373.         return data.integer;
  374.         else return 0;
  375. }
  376.  
  377.  
  378. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  379. //    Routine:        GetMyError
  380. //    Parameters:    none
  381. //    Returns:        an error value
  382. //    Description:
  383. //        Retrieves the error code that the methods that make up this class will
  384. //        generate, in case they had any problems while working.  At the moment, only
  385. //        GetDataWithType:From:  and PutDataWithType: Into:DoIOwn: store error
  386. //        codes..  oh, and so do the two Copy methods..
  387. //        Note that we must access the info directly, and not call GetData, otherwise
  388. //        we'll be mutually recursing for a brief time before we crash.
  389. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  390. - (Integer) GetMyError
  391. {    
  392.     return ReturnVals[MYERROR_RESULT].StoredData.data.integer;
  393. }
  394.  
  395.  
  396. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  397. //    Routine:        GetObject
  398. //    Parameters:    none
  399. //    Returns:        an Object value
  400. //    Description:
  401. //        Retrieves the Object value, if any, from the first storage area.
  402. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  403. - (Instance) GetObject
  404. {
  405.     return [self GetObjectFrom: FIRST_RESULT];
  406. }
  407.  
  408. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  409. //    Routine:        GetObjectFrom:
  410. //    Parameters:    a reference to the storagearea we want to retrieve the value from
  411. //    Returns:        an Object value
  412. //    Description:
  413. //        Retrieves the Object value, if any, from the specified storage area
  414. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  415. - (Instance) GetObjectFrom: (Integer) reference
  416. {
  417.     GenericType data;
  418.     
  419.     data = [self GetDataWithType: TYPE_INSTANCE From: reference];
  420.     if ([self GetMyError] == ERR_OK)
  421.         return data.instance;
  422.         else return 0;
  423. }
  424.  
  425.  
  426. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  427. //    Routine:        GetPointer
  428. //    Parameters:    none
  429. //    Returns:        a pointer value
  430. //    Description:
  431. //        Retrieves the pointer value, if any, from the first storage area.  It does NOT
  432. //        make a copy of the pointer data.
  433. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  434. - (Pointer) GetPointer
  435. {
  436.     return [self GetPointerFrom: FIRST_RESULT];
  437. }
  438.  
  439.  
  440. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  441. //    Routine:        GetPointerFrom:
  442. //    Parameters:    an integer indicating what storage area to retrieve from
  443. //    Returns:        a pointer value
  444. //    Description:
  445. //        Retrieves the pointer value, if any, from the specified storage are.  It does NOT
  446. //        make a copy of the pointer data.
  447. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  448. - (Pointer) GetPointerFrom: (Integer) reference
  449. {
  450.     GenericType data;
  451.     
  452.     data = [self GetDataWithType: TYPE_POINTER From: reference];
  453.     if ([self GetMyError] == ERR_OK)
  454.         return data.pointer;
  455.         else return NullPointer;
  456. }
  457.  
  458.  
  459. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  460. //    Routine:        GetPositiveInteger
  461. //    Parameters:    none
  462. //    Returns:        a positive integer value
  463. //    Description:
  464. //        Retrieves the positiveinteger value, if any, from the first storage area.
  465. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  466. - (PositiveInteger) GetPositiveInteger
  467. {
  468.     return [self GetPositiveIntegerFrom: FIRST_RESULT];
  469. }
  470.  
  471.  
  472. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  473. //    Routine:        GetPositiveIntegerFrom:
  474. //    Parameters:    an integer indicating which storage area to retrieve from
  475. //    Returns:        a PositiveInteger value
  476. //    Description:
  477. //        Retrieves the integer value, if any, from the storage area specified.
  478. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  479. - (PositiveInteger) GetPositiveIntegerFrom: (PositiveInteger) reference
  480. {
  481.     GenericType data;
  482.     
  483.     data = [self GetDataWithType: TYPE_POSITIVEINTEGER From: reference];
  484.     if ([self GetMyError] == ERR_OK)
  485.         return data.positiveinteger;
  486.         else return 0;
  487. }
  488.  
  489.  
  490. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  491. //    Routine:        PutBoolean:Into:
  492. //    Parameters:    data item, and location to store it
  493. //    Returns:        self
  494. //    Description:
  495. //        Stores the specified data in the specified storage area.  To do this, we build
  496. //    a data type with our data and its type, and then we ask to store it properly.
  497. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  498. - (Instance) PutBoolean: (Boolean) data Into: (Integer) reference
  499. {
  500.     GenericType    theData;
  501.  
  502.     theData.boolean = data;
  503.     [self PutData: theData WithType: TYPE_BOOLEAN  Into: reference DoIOwn: YES];
  504.     return self;
  505. }
  506.  
  507.  
  508. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  509. //    Routine:        PutCharacter:Into:
  510. //    Parameters:    data item, and location to store it
  511. //    Returns:        self
  512. //    Description:
  513. //        Stores the specified data in the specified storage area.  To do this, we build
  514. //    a data type with our data and its type, and then we ask to store it properly.
  515. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  516. - (Instance) PutCharacter: (Character) data Into: (Integer) reference
  517. {
  518.     GenericType    theData;
  519.  
  520.     theData.character = data;
  521.     [self PutData: theData WithType: TYPE_CHARACTER  Into: reference DoIOwn: YES];
  522.     return self;
  523. }
  524.  
  525.  
  526. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  527. //    Routine:        PutCString:Into:
  528. //    Parameters:    data item, and location to store it
  529. //    Returns:        self
  530. //    Description:
  531. //        Stores the specified data in the specified storage area.  To do this, we build
  532. //    a data type with our data and its type, and then we ask to store it properly.
  533. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  534. - (Instance) PutCString: (CString) data Into: (Integer) reference
  535. {
  536.     GenericType    theData;
  537.  
  538.     theData.cstring = data;
  539.     [self PutData: theData WithType: TYPE_CSTRING  Into: reference DoIOwn: NO];
  540.     return self;
  541. }
  542.  
  543.  
  544. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  545. //    Routine:        PutData:Into:DoIOwn:
  546. //    Parameters:    data to be stored, which storage area to put it in, and whether we own it
  547. //    Returns:        self
  548. //    Description:
  549. //        If we are trying to store in an area that we shouldn't be, then return an error and
  550. //        don't store anything.  Otherwise copy our information into the storage area.
  551. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  552. - (Instance) PutData: (GenericType) theData WithType: (Integer) theType
  553.     Into: (Integer) storage DoIOwn: (Boolean) ownit
  554. {
  555.     Integer status;
  556.     
  557.     if ((storage > MAXAREAS -1) || (storage < 0))
  558.         status = ERR_NOSUCHAREA;
  559.     else
  560.     {
  561.         ReturnVals[storage].IOwnData = ownit;
  562.         ReturnVals[storage].StoredData.data= theData;
  563.         ReturnVals[storage].StoredData.type= theType;
  564.         status = ERR_OK;
  565.     }
  566.     [self StoreMyError: status];
  567.     return self;
  568. }
  569.  
  570.  
  571. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  572. //    Routine:        PutInteger:Into:
  573. //    Parameters:    data item, and location to store it
  574. //    Returns:        self
  575. //    Description:
  576. //        Stores the specified data in the specified storage area.  To do this, we build
  577. //    a data type with our data and its type, and then we ask to store it properly.
  578. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  579. - (Instance) PutInteger: (Integer) data Into: (Integer) reference
  580. {
  581.     GenericType    theData;
  582.  
  583.     theData.integer = data;
  584.      [self PutData: theData WithType: TYPE_INTEGER  Into: reference DoIOwn: YES];
  585.     return self;
  586. }
  587.  
  588.  
  589. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  590. //    Routine:        PutObject:Into:
  591. //    Parameters:    data item, and location to store it
  592. //    Returns:        self
  593. //    Description:
  594. //        Stores the specified data in the specified storage area.  To do this, we build
  595. //    a data type with our data and its type, and then we ask to store it properly.
  596. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  597. - (Instance) PutObject: (Instance) data Into: (Integer) reference
  598. {
  599.     GenericType    theData;
  600.  
  601.     theData.instance = data;
  602.     [self PutData: theData WithType: TYPE_INSTANCE  Into: reference DoIOwn: NO];
  603.     return self;
  604. }
  605.  
  606.  
  607. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  608. //    Routine:        PutPointer:Into:
  609. //    Parameters:    data item, and location to store it
  610. //    Returns:        self
  611. //    Description:
  612. //        Stores the specified data in the specified storage area.  To do this, we build
  613. //    a data type with our data and its type, and then we ask to store it properly.
  614. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  615. - (Instance) PutPointer: (Pointer) data Into: (Integer) reference
  616. {
  617.     GenericType    theData;
  618.  
  619.     theData.pointer = data;
  620.     [self PutData: theData WithType: TYPE_POINTER Into: reference DoIOwn: NO];
  621.     return self;
  622. }
  623.  
  624.  
  625. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  626. //    Routine:        PutPositiveInteger:Into:
  627. //    Parameters:    data item, and location to store it
  628. //    Returns:        self
  629. //    Description:
  630. //        Stores the specified data in the specified storage area.  To do this, we build
  631. //    a data type with our data and its type, and then we ask to store it properly.
  632. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  633. - (Instance) PutPositiveInteger: (PositiveInteger) data Into: (Integer) reference
  634. {
  635.     GenericType    theData;
  636.     
  637.     theData.positiveinteger = data;
  638.     [self PutData: theData WithType: TYPE_POSITIVEINTEGER Into: reference DoIOwn: YES];
  639.     return self;
  640. }
  641.  
  642.  
  643. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  644. //    Routine:        ResetResults
  645. //    Parameters:    none
  646. //    Returns:        self
  647. //    Description:
  648. //        This clears all the result storage areas.  This is accomplished by:
  649. //            (1) Freeing any strings or pointers we own
  650. //            (2) Setting all data items to a type of TYPE_NONE
  651. //            (3) (this is redundant) putting 0 into each storage data item
  652. //        This is accomplished by first checking if we own the data, and if so, if it is a poiner
  653. //        or a CString. If so, then we take the data, and implicitly cast it as a char* and free it.
  654. //        In any case, we then set the type of the data storage area to no data type, and clear
  655. //        the data item (again, implicitly casting the data item to do this).  This implicit
  656. //        casting can be done because the ultimate data item is a union with multiple types
  657. //        unioned in it.  =)
  658. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  659. - (Instance) ResetResults
  660. {
  661.     Integer    index;
  662.     StorageArea*    SA;    // pointer to the storage area we want to work on.
  663.     
  664.     for (index = 0; index < MAXAREAS; index++)
  665.     {
  666.         SA = &ReturnVals[index];    // Esentially doing a pascal WITH ReturnVals[index]...
  667.         if ((SA->IOwnData == YES) &&
  668.             ((SA->StoredData.type == TYPE_CSTRING) ||
  669.             (SA->StoredData.type == TYPE_POINTER)))
  670.             free(SA->StoredData.data.cstring);
  671.         SA->StoredData.type = TYPE_NONE;
  672.         SA->StoredData.data.integer = 0;
  673.         SA->IOwnData = NO;
  674.     }
  675.     //
  676.     //    Special case.  put a empty CString into the error text, to allow for sloppy
  677.     //    programming.
  678.     //
  679.     [self PutCString: "" Into: ERRORTEXT_RESULT];
  680.     return self;
  681. }
  682.  
  683.  
  684. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  685. //    Routine:        StoreErrorCode:AndText:
  686. //    Parameters:    an error code and an error string to be stored for the callser to find
  687. //    Returns:        self
  688. //    Description:
  689. //        This stores the error code and error string into the result areas reserved for
  690. //        them, and returns self.
  691. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  692. - (Instance) StoreErrorCode: (Integer) code AndText: (CString) text
  693. {
  694.     [self PutInteger: code Into: ERRORCODE_RESULT];
  695.     [self PutCString: text Into: ERRORTEXT_RESULT];
  696.     return self;
  697. }
  698.  
  699.  
  700. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  701. //    Routine:        StoreErrorCode:AndCopyOfText:
  702. //    Parameters:    an error code and an error string to be stored for the callser to find
  703. //    Returns:        self
  704. //    Description:
  705. //        This stores its the error code, and a full copy of the error text in the result
  706. //        areas reserved for these purposes..
  707. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  708. - (Instance) StoreErrorCode: (Integer) code AndCopyOfText: (CString) text
  709. {
  710.     [self PutInteger: code Into: ERRORCODE_RESULT];
  711.     [self CopyCString: text Into: ERRORTEXT_RESULT];
  712.     return self;
  713. }
  714.  
  715.  
  716. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  717. //    Routine:        StoreBoolean:
  718. //    Parameters:    a Boolean
  719. //    Returns:        self
  720. //    Description:
  721. //        This stores its data into the first result storage area, and returns self.
  722. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  723. - (Instance) StoreBoolean: (Boolean) data
  724. {
  725.     return [self PutBoolean: data Into: FIRST_RESULT];
  726. }
  727.  
  728.  
  729. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  730. //    Routine:        StoreCharacter:
  731. //    Parameters:    a Character
  732. //    Returns:        self
  733. //    Description:
  734. //        This stores its data into the first result storage area, and returns self.
  735. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  736. - (Instance) StoreCharacter: (Character) data
  737.     { return [self PutCharacter: data Into: FIRST_RESULT]; }
  738.  
  739.  
  740. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  741. //    Routine:        StoreCString:
  742. //    Parameters:    a CString
  743. //    Returns:        self
  744. //    Description:
  745. //        This stores its data into the first result storage area, and returns self.
  746. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  747. - (Instance) StoreCString: (CString) data
  748. {
  749.     return [self PutCString: data Into: FIRST_RESULT];
  750. }
  751.  
  752.  
  753. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  754. //    Routine:        StoreInteger:
  755. //    Parameters:    an Integer
  756. //    Returns:        self
  757. //    Description:
  758. //        This stores its data into the first result storage area, and returns self.
  759. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  760. - (Instance) StoreInteger: (Integer) data
  761. {
  762.     return [self PutInteger: data Into: FIRST_RESULT];
  763. }
  764.  
  765.  
  766. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  767. //    Routine:        StoreMyError:
  768. //    Parameters:    an Integer
  769. //    Returns:        self
  770. //    Description:
  771. //        This stores its data into the the error register used for our own error generation
  772. //        Note that this must do this nasty work itself, rather than using, say,
  773. //        PutInteger:Into:, cause otherwise it's very likely you'll have an infinite loop
  774. //        on your hand...  nasty
  775. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  776. - (Instance) StoreMyError: (Integer) data
  777. {
  778.     ReturnVals[MYERROR_RESULT].IOwnData = YES;
  779.     ReturnVals[MYERROR_RESULT].StoredData.data.integer= data;
  780.     ReturnVals[MYERROR_RESULT].StoredData.type= TYPE_INTEGER;
  781.     return self;
  782. }
  783.  
  784.  
  785. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  786. //    Routine:        StoreObject:
  787. //    Parameters:    an Object
  788. //    Returns:        self
  789. //    Description:
  790. //        This stores its data into the first result storage area, and returns self.
  791. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  792. - (Instance) StoreObject: (Instance) data
  793. {
  794.     return [self PutObject: data Into: FIRST_RESULT];
  795. }
  796.  
  797.  
  798. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  799. //    Routine:        StorePointer:
  800. //    Parameters:    a Pointer
  801. //    Returns:        self
  802. //    Description:
  803. //        This stores its data into the first result storage area, and returns self.
  804. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  805. - (Instance) StorePointer: (Pointer) data
  806. {
  807.     return [self PutPointer: data Into: FIRST_RESULT];
  808. }
  809.  
  810.  
  811. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  812. //    Routine:        StorePositiveInteger:
  813. //    Parameters:    a PositiveInteger
  814. //    Returns:        self
  815. //    Description:
  816. //        This stores its data into the first result storage area, and returns self.
  817. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  818. - (Instance) StorePositiveInteger: (PositiveInteger) data
  819. {
  820.     return [self PutPositiveInteger: data Into: FIRST_RESULT];
  821. }
  822. @end
  823.